#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>

#define CLOSE_CMD 			(_IO(0XEF, 0x1))
#define OPEN_CMD 			(_IO(0XEF, 0x2))
#define SETPEROD_CMD 		(_IO(0XEF, 0x3))

int main(int argc, char **argv)
{
	int fd;
	int cmd=0;
	int arg=0;
	int ret;
	char str[100];

	if(argc!=2)
	{
		printf("Usage error %s\r\n",argv[0]);
		return -EINVAL;
	}

	fd = open(argv[1],O_RDWR);
	if(fd <0)
	{
		printf("open error\r\n");
		return -EINVAL;
	}

	while(1)
	{
		printf("input cmd:");
		ret = scanf("%d",&cmd);
		if(ret!=1)
			gets(str);

		if(cmd<1 || cmd >3)
			break;
		
		switch(cmd)
		{
			case 1:
				cmd = CLOSE_CMD;
				break;
			
			case 2:
				cmd = OPEN_CMD;
				break;
				
			case 3:
				cmd = SETPEROD_CMD;
				printf("Input Timer Period:");
				ret = scanf("%d",&arg);
				if(ret!=1)
					gets(str);
				break;			
		}
		ioctl(fd,cmd,arg);
	}

	close(fd);
	return 0;
}

